//
//  HPOtherRightView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/4.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "HPOtherRightView.h"

@implementation HPOtherRightView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
        [self initSubView];
    }
    return self;
}
//- (void)initSubView{
//    self.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
//    self.layer.cornerRadius = 5;
//    [self addSubview:self.titleLabel];
//    _titleLabel.hidden = YES;
//    [self addSubview:self.startTimeLabel];
//    _startTimeLabel.hidden = YES;
//    [self addSubview:self.endTimeLabel];
//    _endTimeLabel.hidden = YES;
//    [self addSubview:self.totleLabel];
//    _totleLabel.hidden = YES;
//    [self addSubview:self.noDataLabel];
//    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@15);
//        make.right.equalTo(@0).offset(-15);
//        make.top.equalTo(@15);
//        make.height.equalTo(@14);
//    }];
//    [_startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@15);
//        make.right.equalTo(@0).offset(-15);
//        make.top.equalTo(self.titleLabel.mas_bottom).offset(15);
//        make.height.equalTo(@11);
//    }];
//    [_endTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@15);
//        make.right.equalTo(@0).offset(-15);
//        make.top.equalTo(self.startTimeLabel.mas_bottom).offset(14);
//        make.height.equalTo(@14);
//    }];
//    [_totleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@15);
//        make.right.equalTo(@0).offset(-15);
//        make.top.equalTo(self.endTimeLabel.mas_bottom).offset(15);
//        make.height.equalTo(@12);
//    }];
//    [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@0);
//        make.right.equalTo(@0);
//        make.top.equalTo(@0);
//        make.bottom.equalTo(@0);
//    }];
//}
//- (UILabel *)titleLabel{
//    if (!_titleLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"音标视频督课";
//        label.font = [UIFont systemFontOfSize:14];
//        label.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
//        _titleLabel = label;
//    }
//    return _titleLabel;
//}
//- (UILabel *)startTimeLabel{
//    if (!_startTimeLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"开始日期：2019-02-08";
//        label.font = [UIFont systemFontOfSize:12];
//        label.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
//        _startTimeLabel = label;
//    }
//    return _startTimeLabel;
//}
//- (UILabel *)endTimeLabel{
//    if (!_endTimeLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"结束日期：2019-04-08";
//        label.font = [UIFont systemFontOfSize:12];
//        label.textColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0];
//        _endTimeLabel = label;
//    }
//    return _endTimeLabel;
//}
//- (UILabel *)totleLabel{
//    if (!_totleLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"共 6 人";
//        label.attributedText = [PublickFunctionObject getPriceAttribute:label.text and:[UIColor redColor] andChangeBenginString:@"共" andEndString:@"人" andSize:12];
//        _totleLabel = label;
//    }
//    return _totleLabel;
//}
//- (UILabel *)noDataLabel{
//    if (!_noDataLabel) {
//        UILabel *label = [[UILabel alloc]init];
//        label.text = @"当前数据为空╮(╯_╰)╭";
//        label.textAlignment = 1;
//        _noDataLabel = label;
//    }
//    return _noDataLabel;
//}
//- (void)updateView{
//    if (_dataArray.count>0) {
//        _noDataLabel.hidden = YES;
//        HomeOnlinTrainModel *model = _dataArray[0];
//        _titleLabel.text = model.className;
//        _titleLabel.hidden = NO;
//        _startTimeLabel.text = model.beginDate;
//        _startTimeLabel.hidden = NO;
//        _endTimeLabel.text = model.endDate;
//        _endTimeLabel.hidden = NO;
//        _totleLabel.text = [NSString stringWithFormat:@"共 %@ 人",model.students];
//        _totleLabel.hidden = NO;
//    }
//}
- (void)initSubView{
    self.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    self.layer.cornerRadius = 5;
    _cellView = [[HPLTCellView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    _cellView.tag = 20;
    _cellView.hidden = YES;
    [self addSubview:_cellView];
    [_cellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
    [self addSubview:self.noDataLabel];
    [_noDataLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.bottom.equalTo(@0);
    }];
}
- (void)updateView{
    if (_dataArray.count <=1) {
        //        for (int i = 0; i<4; i++) {
        //            HPLTCellView *cell = (HPLTCellView *)[self viewWithTag:20+i];
        //            cell.hidden = YES;
        //        }
        return;
    }
    //    for (int i = 0; i<_dataArray.count; i++) {
    _noDataLabel.hidden = YES;
    TheNewWorkListModel *model = _dataArray[1];
    _cellView.hidden = NO;
    _cellView.index = 0;
    _cellView.userInteractionEnabled = YES;
    _cellView.titleLabel.attributedText =  [[NSMutableAttributedString alloc] initWithString:model.className attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14],NSForegroundColorAttributeName: TITLECOLOR}];
    _cellView.teacherLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.paperName attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: TITLECOLOR}];
    _cellView.timeLabel.attributedText =[[NSMutableAttributedString alloc] initWithString:model.upLoadDate attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 12],NSForegroundColorAttributeName: TITLECOLOR}];
    NSString *str = [NSString stringWithFormat:@"应交：%@人 实交：%@人  ",model.classStudents,model.submitStudents];
    
    NSMutableAttributedString *attribut = [[NSMutableAttributedString alloc]initWithString:str];
    //目的是想改变 ‘/’前面的字体的属性，所以找到目标的range
    NSRange range1 = [str rangeOfString:@"实交："];
    NSRange range2;
    NSRange pointRange;
    range2 = [str rangeOfString:@"人  "];
    pointRange = NSMakeRange(range1.location+3, range2.location-range1.location-3);
    [attribut addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:pointRange];
    //赋值
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    [attribut addAttributes:dic range:pointRange];
    _cellView.otherLabel.attributedText = attribut;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goZuoYeView:)];
    [_cellView addGestureRecognizer:tap];
    //    }
}
- (void)goZuoYeView:(UITapGestureRecognizer *)gesture{
    HPLTCellView *cellView = (HPLTCellView *)gesture.view;
    TheNewWorkListModel *model = _dataArray[cellView.index];
    self.goZuoYeBlock(model);
}
- (UILabel *)noDataLabel{
    if (!_noDataLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text = @"当前数据为空";
        label.textAlignment = 1;
        _noDataLabel = label;
    }
    return _noDataLabel;
}
@end
